from django.db import models
from django.contrib.auth.models import User
import decimal

# Create your models here.

#class for illustrations
class ArtWork(models.Model):
    genre = models.CharField(max_length=50)
    title = models.CharField(max_length=50)
    rate=models.IntegerField()
    votes=models.IntegerField()
    path=models.CharField(max_length=900)
    of=models.ForeignKey(User)

    #calculates the average rating for the work
    def vote(self):
        if (self.votes==0):
            return 0
        else:
            decimal.getcontext().prec = 2
            return decimal.Decimal(self.rate)/decimal.Decimal(self.votes)
        
class Comic(models.Model):
    genre = models.CharField(max_length=50)
    title = models.CharField(max_length=50)
    rate=models.IntegerField()
    votes=models.IntegerField()
    path=models.CharField(max_length=900)
    of=models.ForeignKey(User)
    introduction = models.CharField(max_length=2000)
    abstract= models.CharField(max_length=2000)
    def vote(self):
        if (self.votes==0):
            return 0
        else:
            decimal.getcontext().prec = 2
            return decimal.Decimal(self.rate)/decimal.Decimal(self.votes)

#class for written work
class WrittenWork(models.Model):
    genre = models.CharField(max_length=50)
    introduction = models.CharField(max_length=2000)
    abstract= models.CharField(max_length=2000)
    title = models.CharField(max_length=50)
    rate=models.IntegerField()
    votes=models.IntegerField()
    of=models.ForeignKey(User)

    #calculates the average rating for the work
    def vote(self):
        if (self.votes==0):
            return 0
        else:
            decimal.getcontext().prec = 2
            return decimal.Decimal(self.rate)/decimal.Decimal(self.votes)
